home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / e_SML / dirdiff.sml < prev    next >
Encoding:
Text File  |  1997-07-25  |  6.5 KB  |  230 lines  |  [TEXT/Moml]

  1. (* dirdiff.sml *)
  2. (* 25Jul97   e *)
  3.  
  4. load "FileSys";
  5. load "Path";
  6. load "Time";
  7. load "Date";
  8. load "String";
  9.  
  10. (* requires copyrelease.sml *)
  11. (*
  12. load "Process";
  13. val home =
  14.   case Process.getEnv "PATH_TRANSLATED" of
  15.     SOME n => Path.dir n
  16.   | NONE => ":"
  17. ;
  18.  use (home ^ "e_SML:copyrelease.sml");
  19. *)
  20.  
  21. open FileSys
  22.  
  23. datatype diff = SAME
  24.               | ADDED of string
  25.               | DELETED of string
  26.               | TIME of string * Time.time * Time.time
  27.               | SIZE of string * int * int
  28.               | ERROR of string
  29.  
  30. fun dif_files old new =
  31.   if access (old, [])
  32.   then if access (new, [])
  33.        then if modTime old = modTime new
  34.             then if fileSize old = fileSize new
  35.                  then SAME
  36.                  else SIZE (old, fileSize old, fileSize new)
  37.             else TIME (old, modTime old, modTime new)
  38.        else DELETED old
  39.   else ERROR old
  40.  
  41. fun dif_dirs old new =
  42.   let val dir = openDir old
  43.       val _   =   chDir old
  44.       val result = ref []
  45.       fun comp_file fname =
  46.         let val {base, ext} = Path.splitBaseExt fname
  47.             val tname = Path.joinDirFile {dir = new, file = fname }
  48.         in if isDir fname
  49.            then () (* do nested dirs? *)
  50.            else if (case ext of SOME "ui" => true
  51.                               | SOME "uo" => true 
  52.                               | _ => false)
  53.            then ()
  54.            else case dif_files fname tname of
  55.                   SAME => ()
  56.                 | x => result := x :: (!result)
  57.         end
  58.       fun comp "" = ()
  59.         | comp f  = ( comp_file f ; comp (readDir dir) )
  60.   in
  61.      let val _ = comp (readDir dir)
  62.      in closeDir dir; !result
  63.      end
  64.      handle exn as OS.SysErr (msg, _) => (closeDir dir; raise exn)
  65.   end
  66. ;
  67.  
  68. fun dib_files old new =
  69.   if access (old, [])
  70.   then if access (new, [])
  71.        then SAME (* well, dif already checked so we needn't bother *)
  72.        else ADDED old
  73.   else ERROR old
  74.  
  75. fun dib_dirs old new resf =
  76.   let val dir = openDir old
  77.       val _   =   chDir old
  78.       val result = ref resf
  79.       fun comp_file fname =
  80.         let val {base, ext} = Path.splitBaseExt fname
  81.             val tname = Path.joinDirFile {dir = new, file = fname }
  82.         in if isDir fname
  83.            then () (* do nested dirs? *)
  84.            else if (case ext of SOME "ui" => true
  85.                               | SOME "uo" => true 
  86.                               | _ => false)
  87.            then ()
  88.            else case dib_files fname tname of
  89.                   SAME => ()
  90.                 | x => result := x :: (!result)
  91.         end
  92.       fun comp "" = ()
  93.         | comp f  = ( comp_file f ; comp (readDir dir) )
  94.   in
  95.      let val _ = comp (readDir dir)
  96.      in closeDir dir; !result
  97.      end
  98.      handle exn as OS.SysErr (msg, _) => (closeDir dir; raise exn)
  99.   end
  100. ;
  101.  
  102. fun diff_dirs old new = dib_dirs new old (dif_dirs old new);
  103.  
  104. fun show_diffs difs =
  105.   let fun print_sps x =
  106.         let val z = (14 - (String.size x))
  107.         in
  108.           if z < 0
  109.           then print " "
  110.           else print (String.substring ("                        ",0,z))
  111.         end
  112.       fun sdif SAME = ()
  113.         | sdif (ADDED s) =
  114.             (print "Added:   "; print s; print "\n")
  115.         | sdif (DELETED s) =
  116.             (print "Removed: "; print s; print "\n")
  117.         | sdif (TIME (s,t1,t2)) = 
  118.             ((if Time.> (t2, t1)
  119.              then print "Changed: "
  120.              else print "Revertd: ");
  121.             print s; print_sps s; 
  122.             print (Date.toString(Date.fromTime(t1))); print " - " ;
  123.             print (Date.toString(Date.fromTime(t2))); print "\n")
  124.         | sdif (SIZE (s,z1,z2)) = 
  125.             (print "SizeErr: "; print s; print "\n")
  126.         | sdif (ERROR s) = 
  127.             (print "ProbErr: "; print s; print "\n")
  128.       fun sdifs [] = ()
  129.         | sdifs (d::r) = (sdif d; sdifs r)
  130.   in
  131.     sdifs difs
  132.   end
  133. ;
  134.  
  135. (* requires copyrelease.sml *)
  136.  
  137. fun copy_diffs difs new tgt =
  138.   let val () = ensure_dir tgt
  139.       fun copy_file name =
  140.         let val fname = Path.joinDirFile {dir = new, file = name }
  141.             val tname = Path.joinDirFile {dir = tgt, file = name }
  142.         in
  143.            copy_txt_file fname tname
  144.         end
  145.       fun sdif SAME = ()
  146.         | sdif (ADDED s) = copy_file s
  147.         | sdif (DELETED s) = ()
  148.         | sdif (TIME (s,t1,t2)) = copy_file s
  149.         | sdif (SIZE (s,z1,z2)) = copy_file s
  150.         | sdif (ERROR s) = ()
  151.       fun sdifs [] = ()
  152.         | sdifs (d::r) = (sdif d; sdifs r)
  153.   in
  154.     sdifs difs
  155.   end
  156. ;
  157.  
  158. fun compare_copied_diffs difs new tgt =
  159.   let fun cmp_file name =
  160.         let val fname = Path.joinDirFile {dir = new, file = name }
  161.             val tname = Path.joinDirFile {dir = tgt, file = name }
  162.         in
  163.            compare_files fname tname
  164.         end
  165.       fun sdif SAME = ()
  166.         | sdif (ADDED s) = cmp_file s
  167.         | sdif (DELETED s) = ()
  168.         | sdif (TIME (s,t1,t2)) = cmp_file s
  169.         | sdif (SIZE (s,z1,z2)) = cmp_file s
  170.         | sdif (ERROR s) = ()
  171.       fun sdifs [] = ()
  172.         | sdifs (d::r) = (sdif d; sdifs r)
  173.   in
  174.     sdifs difs
  175.   end
  176. ;
  177.  
  178. (*
  179.  
  180. val homeold = (home ^ ":releases:142:mosml:src:");
  181. val homenew = (home ^                     "src:");
  182.  
  183. val hometgt = (home ^ ":releases:difs142:");
  184. ensure_dir hometgt;
  185.  
  186. val difs =
  187.  diff_dirs (homeold ^ "compiler") (homenew ^ "compiler");
  188. show_diffs difs;
  189. copy_diffs difs (homenew ^ "compiler") (hometgt ^ "compiler:");
  190. compare_copied_diffs difs (homenew ^ "compiler") (hometgt ^ "compiler:");
  191.  
  192. val difs =
  193.  diff_dirs (homeold ^ "mosmllib") (homenew ^ "mosmllib");
  194. show_diffs difs;
  195. copy_diffs difs (homenew ^ "mosmllib") (hometgt ^ "mosmllib:");
  196. compare_copied_diffs difs (homenew ^ "mosmllib") (hometgt ^ "mosmllib:");
  197.  
  198. val difs =
  199.  diff_dirs (homeold ^ "runtime") (homenew ^ "!runtime");
  200. show_diffs difs;
  201. copy_diffs difs (homenew ^ "!runtime") (hometgt ^ "runtime:");
  202. compare_copied_diffs difs (homenew ^ "!runtime") (hometgt ^ "runtime:");
  203.  
  204. val difs =
  205.  diff_dirs (homeold ^ "lex") (homenew ^ "lex");
  206. show_diffs difs;
  207. copy_diffs difs (homenew ^ "lex") (hometgt ^ "lex:");
  208. compare_copied_diffs difs (homenew ^ "lex") (hometgt ^ "lex:");
  209.  
  210. val difs =
  211.  diff_dirs (homeold ^ "toolssrc") (homenew ^ "toolssrc");
  212. show_diffs difs;
  213. copy_diffs difs (homenew ^ "toolssrc") (hometgt ^ "toolssrc:");
  214. compare_copied_diffs difs (homenew ^ "toolssrc") (hometgt ^ "toolssrc:");
  215.  
  216. (* move testbadl temporarily... *)
  217.  
  218. val difs =
  219.  diff_dirs (homeold ^ "mosmllib:test") (homenew ^ "mosmllib:test");
  220. show_diffs difs;
  221. copy_diffs difs (homenew ^ "mosmllib:test") (hometgt ^ "mosmllib:test:");
  222. compare_copied_diffs difs (homenew ^ "mosmllib:test") (hometgt ^ "mosmllib:test:");
  223.  
  224. val difs =
  225.  diff_dirs (homeold ^ "mosmlyac") (homenew ^ "mosmlyac");
  226. show_diffs difs;
  227. (* copy by hand *)
  228.  
  229. *)
  230.